package ltd.followkba.comment.utils;

import java.io.IOException;

import ltd.followkba.comment.MUTIL;

public class CFile16bDbs extends CFileDbs {

    @Override
    public void seek(int offset){
        try {
            mAccessFile.seek(16 + (offset * 16));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void writeUserID(int offset, String userID){
        byte[] gpLocal_1 = MUTIL.MSTRING_16BYTE_ID(userID);
        try {
            int g4Local_1 = 16 + (offset * 16);
            mAccessFile.seek(g4Local_1);
            mAccessFile.write(gpLocal_1);
            if (g4Local_1 >= mLength) {
                mLength = g4Local_1 + 16;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public String readUserID(int offset){
        try {
            mAccessFile.seek(16 + (offset * 16));
            byte[] gpLocal_1 = new byte[16];
            mAccessFile.read(gpLocal_1);
            return MUTIL.M16BYTE_ID_STRING(gpLocal_1);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "00000000-0000-0000-0000-000000000000";
    }

    public void SetUserID16Byte(String userID, String parameter){
        byte[] gpLocal_1 = MUTIL.MSTRING_16BYTE_ID(userID);
        byte[] gpLocal_2 = new byte[16];
        try {
            int g4Local_1 = 16;
            while (g4Local_1 < mLength) {
                mAccessFile.seek(g4Local_1);
                mAccessFile.read(gpLocal_2);
                if (gpLocal_1.equals(gpLocal_2)){
                    break;
                }
                g4Local_1 += (16+16);
            }
            if (g4Local_1 == mLength){                     // 还没有存在
                mAccessFile.seek(g4Local_1);
                mAccessFile.write(gpLocal_1);
                mLength += (16+16);
            }
            else {
                mAccessFile.seek(g4Local_1+16);
            }
            gpLocal_2 = MUTIL.MSTRING_16BYTE_ID(parameter);
            mAccessFile.write(gpLocal_2);
        } catch (IOException e) {
        }
    }
}
